package com.chen.Dome2UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPClientDome1 {
    public static void main(String[] args) throws Exception {
        //目标：完成UDP通信的客户端，一发一收
        //1.创建发送端的对象，并且发送数据
        System.out.println("发送端已经启动...");
        DatagramSocket ds = new DatagramSocket();//创建发送端的对象,生成随机端口号
        byte[] by = "你好，我是客户端".getBytes();
            /*
            参数一:数据源
            参数二:长度
            参数三:接收端的ip地址
            参数四:接收端的端口号
            public DatagramPacket(byte[] buf, int length, InetAddress address, int port)
             */
        DatagramPacket dp = new DatagramPacket(by, by.length, InetAddress.getByName("127.0.0.1"), 10000);
        //3.让发送端发送数据
        ds.send(dp);


    }
}
